using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using gma.System.Windows;
using System.Threading;

namespace Lyxite.CatKingdom
{
    public partial class MainForm : Form
    {
        KeyListener listener;
        UserActivityHook hook;

        public MainForm()
        {
            hook = new UserActivityHook(false, true);
            listener = new KeyListener();

            hook.KeyDown += listener.KeyDown;
            hook.KeyPress += listener.KeyPress;
            hook.KeyUp += listener.KeyUp;

            listener.EnabledChanged += new EventHandler(cat_EnabledChanged);
            
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // global exception handling
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

            // don't show form
            Hide();
        }

        void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            new ThreadExceptionDialog(e.Exception).ShowDialog(this);
        }

        void cat_EnabledChanged(object sender, EventArgs e)
        {
            enableToolStripMenuItem.Checked = listener.Enabled;
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void enableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            listener.Enabled = !enableToolStripMenuItem.Checked;
        }
    }
}